function addfriend($user1,$user2){
	var u1 = $user1;
	var u2 = $user2;
 	$.ajax({
			url:'http://localhost/zf/hoidap/source/index.php/friendship/index/addfriend',
			type:'post',
			dataType:'html',
			data:{user1:u1, user2:u2},
			success:function(data){
				var obj = jQuery.parseJSON(data);
				var name_f_r = obj.name_f_r;
				//alert('Them ban thanh cong');
				$('.div_ctn_tb').append("<li class='cursor_d bd_bottom request_ketban_"+u1+"'><div class='img_user_tb'><img src='/zf/hoidap/source/public/images/ava.jpg' alt='' title='user'/></div><div class='nd_tb'><div class='title_tb'>"+name_f_r+"</div><div class='date_tb'>Khoảng 3 ngày trước</div><div class='xacnhan_kb_1 xn_kb_"+u1+"'><a onclick='xacnhanketban("+u1+", "+u2+");' href='javascript:;'>Xác nhận</a></div><div class='xacnhan_kb_2 kpln_kb_"+u1+"'><a onclick='khongphailucnay("+u1+", "+u2+");' href='javascript:;'>Không phải lúc này</a></div></div></li>");
			}
		});
}
function getnumrequestfriendships($iduser){
	$tong = document.getElementById('num_request_kb').innerHTML;
	var iu = $iduser;
	$.ajax({
			url:'http://localhost/zf/hoidap/source/index.php/friendship/index/getnumrequestfriendships',
			type:'post',
			data:{iduser:iu, tong:$tong},
			success:function(data){
				var obj = jQuery.parseJSON(data);
				
				var num_friend_request = obj.num_friend_request;
				if(num_friend_request!=0){	
					//alert(obj.array_friend_request['1']['friendrequest']);
					$('.rq_tb_kb').css("display","inline");
					$('.num_request_kb').html(num_friend_request);
				}else if(num_friend_request==0){
					$('.rq_tb_kb').css("display","none");
				}
			}
		});
}

function xacnhanketban($user1, $user2){
	var iu1 = $user1;
	var iu2 = $user2;
	$.ajax({
		url:'http://localhost/zf/hoidap/source/index.php/friendship/index/acceptrequestfriends',
		type:'post',
		data:{iduser1:iu1, iduser2:iu2},
		success:function(data){
				//alert(data);
				$('.xn_kb_'+iu1).fadeOut();
				$('.kpln_kb_'+iu1).fadeOut();
				return false;
			}
	});	
}

function khongphailucnay($user1, $user2){
	var iu1 = $user1;
	var iu2 = $user2;
	$.ajax({
		url:'http://localhost/zf/hoidap/source/index.php/friendship/index/unacceptrequestfriends',
		type:'post',
		data:{iduser1:iu1, iduser2:iu2},
		success:function(data){
				//alert(data);
				//$('.xn_kb_'+iu1).fadeOut();
				//$('.kpln_kb_'+iu1).fadeOut();
				$('li.request_ketban_'+iu1).fadeOut();
				return false;
			}
	});
}

//function getuserrequestfriendships($iduser){
//	var iu = $iduser;
//	$.ajax({
//		url:'http://localhost/zf/hoidap/source/index.php/friendship/index/unacceptrequestfriends',
//		type:'post',
//		data:{iduser1:iu1, iduser2:iu2},
//		success:function(data){
//				//alert(data);
//				//$('.xn_kb_'+iu1).fadeOut();
//				//$('.kpln_kb_'+iu1).fadeOut();
//				$('li.request_ketban_'+iu1).fadeOut();
//				return false;
//			}
//	});
//}

$(document).ready(function(){
	var iduser = document.getElementById('input_iduser').value;
	setInterval(function () {
		getnumrequestfriendships(iduser);
		getuserrequestfriendships(iduser);
	}, 2000);
	
	$('.nd_ketban').click(function(){
		return false;
	});
});


$(document).ready(function(){
	$('.nd_ketban').hide();
	$('.nd_tinnhan').hide();
	$('.nd_thongbao').hide();
	$('li.tb_ketban').live('click',function(){
		$('.nd_ketban').show(); $('.nd_tinnhan').hide(); $('.nd_thongbao').hide();
		$('.tb_ketban').addClass('tb_ketban_on');
		$('.tb_tinnhan_on').removeClass('tb_tinnhan_on');
		$('.tb_thongbao_on').removeClass('tb_thongbao_on');
	});
	$('li.tb_ketban_on').live('click',function(){
		$('.nd_ketban').hide(); $('.tb_ketban_on').removeClass('tb_ketban_on');
	});
	
	$('.tb_tinnhan').live('click',function(){
		$('.nd_ketban').hide(); $('.nd_tinnhan').show(); $('.nd_thongbao').hide();
		$('.tb_tinnhan').addClass('tb_tinnhan_on');
		$('.tb_ketban_on').removeClass('tb_ketban_on');
		$('.tb_thongbao_on').removeClass('tb_thongbao_on');
	});
	$('.tb_tinnhan_on').live('click',function(){
		$('.nd_tinnhan').hide(); $('.tb_tinnhan_on').removeClass('tb_tinnhan_on');
	});
	
	$('.tb_thongbao').live('click',function(){
		$('.nd_ketban').hide(); $('.nd_tinnhan').hide(); $('.nd_thongbao').show();
		$('.tb_thongbao').addClass('tb_thongbao_on');
		$('.tb_ketban_on').removeClass('tb_ketban_on');
		$('.tb_tinnhan_on').removeClass('tb_tinnhan_on');
	});
	$('.tb_thongbao_on').live('click',function(){
		$('.nd_thongbao').hide(); $('.tb_thongbao_on').removeClass('tb_thongbao_on');
	});
});